package ui.timeline;

import javax.swing.JSlider;


public class TwoThumbTimeLineSlider extends JSlider {

    /**
	 * 
	 */
	private static final long serialVersionUID = 8942286590518918775L;
	/**
     * Constructs a RangeSlider with default minimum and maximum values of 0
     * and 100.
     */
	public int trackHeight = 10;
	public int minSlider;
	public int maxSlider;

	public int upperValue;
	
	public long beginTime;
	private int lowerValue;
    
    public int getLowerValue()
    {
    	return lowerValue;
    }
    
    public void setLowerValue(int value)
    {
    	this.lowerValue = value;
    }
    /**
     * Constructs a RangeSlider with the specified default minimum and maximum 
     * values.
     */
    public TwoThumbTimeLineSlider(long beginTime, long endTime) {
        super(0, (int)(endTime-beginTime));
        
        this.beginTime = beginTime;
        this.minSlider = 0;
        this.maxSlider = (int) (endTime-beginTime);

        this.setValue(100);
        this.setUpperValue((int) (endTime-beginTime));

        setOrientation(HORIZONTAL);
        
    	getModel().setRangeProperties(this.minSlider , this.maxSlider - this.minSlider, this.getValue(), this.maxSlider, getValueIsAdjusting());

    }
    
    public long getBeginTime()
    {
    	return this.beginTime;
    }
    /**
     * Overrides the superclass method to install the UI delegate to draw two
     * thumbs.
     */
    @Override
    public void updateUI() {
        setUI(new TwoThumbTimeLineSliderUI(this));
        // Update UI for slider labels.  This must be called after updating the
        // UI of the slider.  Refer to JSlider.updateUI().
        updateLabelUIs();
    }


    
    /**
     * Returns the upper value in the range.
     */
    public int getUpperValue() {
        return upperValue;
    }

    /**
     * Sets the upper value in the range.
     */
    public void setUpperValue(int value) {
    	if(value >= this.getValue())
    	{
    		this.upperValue = value;
    	}
    	else
    	{
    		this.upperValue = this.getValue();
    	}
    }

	public void repaintCurrentThumb()
	{
		this.updateUI();
	}

	public boolean isDragging()
	{
		return (currentIsDragging() || upperIsDragging());
	}
	
	public boolean currentIsDragging() {
		return ((TwoThumbTimeLineSliderUI)this.getUI()).currentDragging;
	}
	
	public boolean upperIsDragging() {
		return ((TwoThumbTimeLineSliderUI)this.getUI()).upperDragging;
	}
}